package gui;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;

import utils.IntComparator;
import utils.MyTableCellRenderer;
import connection.Sought;

/**
 * Okno pro sought list
 * 
 * @author dove
 * 
 */
public class SoughtWin extends InternalFrame {

	private static final long serialVersionUID = 1L;
	private JTable inbox;
	private JPanel back;
	private DefaultTableModel model;

	private String[] columnNamesSought = { "#", messages.getString("Name"),
			messages.getString("Rating"), messages.getString("Time"),
			messages.getString("Increment"), messages.getString("Rated"),
			messages.getString("Style"), messages.getString("Color") };

	private Object[][] data;
	private Sought sought;

	/**
	 * Nastavuje nazev okna
	 * 
	 * @param name
	 *            nazev okna
	 */
	public SoughtWin(String name) {
		super(name);
	}

	public SoughtWin getWindow() {

		back = new JPanel();

		model = new DefaultTableModel(data, columnNamesSought);

		inbox = new JTable(model);
		inbox.setDefaultRenderer(Object.class, new MyTableCellRenderer());

		TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<DefaultTableModel>(
				model);
		sorter.setComparator(0, new IntComparator());
		sorter.setComparator(2, new IntComparator());
		sorter.setComparator(3, new IntComparator());
		sorter.setComparator(4, new IntComparator());

		inbox.setRowSorter(sorter);
		inbox.setPreferredScrollableViewportSize(new Dimension(400, 356));
		inbox.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		inbox.getColumnModel().getColumn(0).setPreferredWidth(25);
		inbox.getColumnModel().getColumn(1).setPreferredWidth(110);
		inbox.getColumnModel().getColumn(2).setPreferredWidth(45);
		inbox.getColumnModel().getColumn(3).setPreferredWidth(25);
		inbox.getColumnModel().getColumn(4).setPreferredWidth(30);
		inbox.getColumnModel().getColumn(5).setPreferredWidth(70);
		inbox.getColumnModel().getColumn(6).setPreferredWidth(55);
		inbox.getColumnModel().getColumn(7).setPreferredWidth(40);
		inbox.setForeground(Color.BLACK);
		sought = new Sought(model, inbox);

		JScrollPane top = new JScrollPane(inbox);
		back.add(top);
		getContentPane().add(back);

		this.add(back);
		this.setPreferredSize(new Dimension(420, 407));
		this.pack();

		return this;
	}

	/**
	 * Pripojuje k serveru
	 */
	public void connect() {
		sought.connect();
	}
}
